﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FuncFileUseCase.cs" company="">
//   
// </copyright>
// <summary>
//   The func file use case.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.UseCases
{
    using System;

    /// <summary>
    ///   The func file use case.
    /// </summary>
    public class FuncFileUseCase : BaseFileUseCase
    {
        #region Fields

        /// <summary>
        ///   The _get file path.
        /// </summary>
        private readonly Func<string> _getFilePath;

        /// <summary>
        ///   The _set file path.
        /// </summary>
        private readonly Action<string> _setFilePath;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FuncFileUseCase"/> class.
        /// </summary>
        /// <param name="parent">
        /// The parent. 
        /// </param>
        /// <param name="service">
        /// The service. 
        /// </param>
        /// <param name="getFilePath">
        /// The get file path. 
        /// </param>
        /// <param name="setFilePath">
        /// The set file path. 
        /// </param>
        public FuncFileUseCase(
            ICompoundUseCase parent, 
            IUseCaseInstanceService service, 
            Func<string> getFilePath, 
            Action<string> setFilePath)
            : base(parent, service)
        {
            _getFilePath = getFilePath;
            _setFilePath = setFilePath;
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///   Gets or sets the file path.
        /// </summary>
        public override string FilePath
        {
            get
            {
                return _getFilePath();
            }

            set
            {
                var filePath = _getFilePath();
                if (filePath != value)
                {
                    _setFilePath(value);
                    OnFileChanged();
                    Modified = true;
                }
            }
        }

        #endregion
    }
}